package com.heima.estatemanagement.controller;

import com.github.pagehelper.Page;
import com.heima.estatemanagement.common.MessageConstant;
import com.heima.estatemanagement.common.PageResult;
import com.heima.estatemanagement.common.Result;
import com.heima.estatemanagement.common.StatusCode;
import com.heima.estatemanagement.domain.TbParkingUse;
import com.heima.estatemanagement.service.TbParkingUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description: parkingUse类
 * Created by 86191 on 2023/2/6.
 */
@RestController
@RequestMapping("/parkingUse")
public class ParkingUseController {
    @Autowired
    private TbParkingUseService parkingUseService;

    @RequestMapping("/find")
    public Result find(){
        List<TbParkingUse> all = parkingUseService.selectAll();
        return new Result(false,0,"请求成功adasdasdas",all);
    }

    @RequestMapping("/search")
//    public PageResult search(){
        public PageResult search(@RequestBody Map searchMap){
            Page<TbParkingUse> page = parkingUseService.search(searchMap);
        return new PageResult(true, StatusCode.OkLAYUI, MessageConstant.TB_PARKING_SEARCH_SUCCESS,page.getResult(),page.getTotal(),page.getPageSize());
    }

    @RequestMapping("/add")
    public Result add(TbParkingUse parkingUse){
        System.out.println(parkingUse);

//        if (parkingUse.getStartTime().compareTo(parkingUse.getEndTime())>0) {
//            return new Result(true, StatusCode.ERROR, MessageConstant.TB_PARKING_USE_ADD_DATE_EQUALS_ERROR);
//        }
//
        parkingUseService.add(parkingUse);
        return new Result(true,StatusCode.OK,MessageConstant.TB_PARKING_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(int id){
        TbParkingUse parking = parkingUseService.findById(id);
        return new Result(true,StatusCode.OK,MessageConstant.TB_PARKING_USE_FIND_SUCCESS,parking);
    }

    @RequestMapping("/update")
    public Result update(TbParkingUse parkingUse){
        parkingUseService.update(parkingUse);
        return new Result(true,StatusCode.OK,MessageConstant.TB_PARKING_UPDATE_SUCCESS);
    }



//    @RequestMapping("/del")
//    public Result del(@RequestBody List<Integer> ids){
//        Boolean flag = parkingService.del(ids);
//        return new Result(true,StatusCode.OK,MessageConstant.TB_PARKING_DELETE_SUCCESS);
//    }

//    @RequestMapping("/delById")
//    public Result delById(int id){
//        if (parkingService.delFindByStatus(id)){
//            Boolean flag = parkingService.delById(id);
//            return new Result(true,StatusCode.OK,MessageConstant.TB_PARKING_DELETE_SUCCESS);
//        }else{
//            return new Result(true,StatusCode.ERROR,MessageConstant.TB_PARKING_DELETE_ERROR);
//        }
//    }
}
